package com.briup.cms.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @version 1.0
 * @Description
 * @date 2021/7/17 19:26
 */
public class SecurityUtils {
    private static ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<>();

    public static String get(String key) {
        if (threadLocal.get() == null)
            return null;
        return (String)((Map)threadLocal.get()).get(key);
    }

    public static void setMap(Map<String, String> map) {
        threadLocal.set(map);
    }

    public static void setKV(String key, String value) {
        if (threadLocal.get() == null) {
            Map<String, String> map = new HashMap<>();
            threadLocal.set(map);
        }
        ((Map<String, String>)threadLocal.get()).put(key, value);
    }

    public static void setmethod(String method) {
        setKV("method", method);
    }

    public static String getmethod() {
        return get("method");
    }

    public static void setRequestURI(String requestURI) {
        setKV("requestURI", requestURI);
    }

    public static String getRequestURI() {
        return get("requestURI");
    }

    public static void setUsername(String username) {
        setKV("username", username);
    }

    public static String getUsername() {
        return get("username");
    }

    public static void setRealname(String realname) {
        setKV("realname", realname);
    }

    public static String getRealname() {
        return get("realname");
    }
}
